package com.example.arithmeticleetcode.leetcode.october;


import java.util.ArrayList;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-28 09:13
 **/
public class Demo17 {

    public static void main(String[] args) {
        System.out.println(nthUglyNumber(3, 2, 3, 5)); //4
        System.out.println(nthUglyNumber(4, 2, 3, 4)); //6
        System.out.println(nthUglyNumber(5, 2, 11, 13)); //10
        System.out.println(nthUglyNumber(1000000000, 2, 217983653, 336916467)); //1999999984

    }

    public static int nthUglyNumber(int n, int a, int b, int c) {
        int i = Math.min(a, Math.min(b, c));
        int temp = 0;
        do {
            if (i % a == 0 || i % b == 0 ||i % c == 0) {
                temp = i;
                n--;
            }
            i++;
        } while (n > 0);
        return temp;
    }
}
